﻿using System.Collections.Generic;
using System.Data.Linq;
using DataEntities;
using DataProvider;
using SQLDataProvider;

namespace BusinessServices
{
    public class TuiHuanService
    {
        private readonly IBaseRepository<TuiHuanInfo> _tuiHuanRepository;

        public TuiHuanService()
        {
            _tuiHuanRepository = new BaseRepository<TuiHuanInfo>();
        }

        public List<TuiHuanInfo> GetAll()
        {
            return _tuiHuanRepository.GetAll(p => true, JoinKeHuAndCar);
        }

        public List<TuiHuanInfo> GetAllByKeHuId(int keHuId)
        {
            return _tuiHuanRepository.GetAll(p => p.iKeHuId == keHuId, JoinKeHuAndCar);
        }

        private DataLoadOptions JoinKeHuAndCar()
        {
            var loadOption = new DataLoadOptions();
            loadOption.LoadWith<TuiHuanInfo>(p => p.KeHuInfo);
            loadOption.LoadWith<TuiHuanInfo>(p => p.CarInfo);
            return loadOption;
        }

        public TuiHuanInfo Add(TuiHuanInfo tuiHuanInfo)
        {
            return _tuiHuanRepository.Add(tuiHuanInfo);
        }
    }
}
